package com.et114.modules.myet.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.PropertyUtils;

import com.et114.components.simpletable.DataList;
import com.et114.core.resources.MessageManager;
import com.et114.core.services.impl.BaseServicesImpl;
import com.et114.modules.cust.BIZ;
import com.et114.modules.cust.dao.IMng_CustDao;
import com.et114.modules.cust.vo.CustBaseVo;
import com.et114.modules.cust.vo.CustInfoVo;
import com.et114.modules.myet.dao.IMyEt_UCenterDao;
import com.et114.modules.myet.form.EtCarFrom;
import com.et114.modules.myet.vo.MyEtOrder_VO;
import com.et114.modules.order.service.IMng_OrderService;
import com.et114.modules.order.vo.OrderTrack;
import com.et114.modules.order.vo.ProVO;
import com.et114.modules.products.base.ProImage;
import com.et114.modules.products.card.vo.Card;
import com.et114.modules.products.cellphone.vo.CellPhone;
import com.et114.modules.products.commons.Const;
import com.et114.modules.products.commons.ViewsMessageManager;
import com.et114.modules.products.digitalTv.vo.DigitalTv;
import com.et114.modules.products.interfaces.ProInterface;
import com.et114.modules.products.netbook.vo.NetBook;
import com.et114.modules.products.securitydoor.vo.SecurityDoor;
import com.et114.modules.system.dictionary.DictionaryCache;
import com.et114.modules.system.dictionary.vo.BizOption;
import com.et114.modules.system.dictionary.vo.BizType;

/**
 * @author zhiweip
 * @version 1.0
 * @created 22-十二月-2010 13:33:57
 */
public class MyEt_UCenterServiceImp extends BaseServicesImpl implements IMyEt_UCenterService {
	
	public IMyEt_UCenterDao		m_IMyEt_UCenterDao;
	private IMng_CustDao		mng_CustDao;
	private IMng_OrderService	mng_OrderService;
	private ProInterface		proInterface; 
	
	public void setM_IMyEt_UCenterDao ( IMyEt_UCenterDao myEt_UCenterDao ) {
		m_IMyEt_UCenterDao = myEt_UCenterDao;
	}
	
	public void setMng_CustDao ( IMng_CustDao mng_CustDao ) {
		this.mng_CustDao = mng_CustDao;
	}
	
	public void setMng_OrderService ( IMng_OrderService mng_OrderService ) {
		this.mng_OrderService = mng_OrderService;
	}
	
	public void setProInterface ( ProInterface proInterface ) {
		this.proInterface = proInterface;
	}
	
	public MyEt_UCenterServiceImp ( ) {
		
	}
	
	public void finalize ( ) throws Throwable {
		
	}
	
	/**
	 * 我的订单
	 * 
	 * @throws Exception
	 */
	public DataList myOrder ( MyEtOrder_VO vo ) throws Exception {
		if ( null == vo.getLanguage ( ) || "".equals ( vo.getLanguage ( ) ) ) {
			vo.setLanguage ( "zh" );
		}
		
		String lang=vo.getLanguage ( );
		//System.out.println ("============lang: "+lang);
		DataList dList = m_IMyEt_UCenterDao.queryMyETOrderDataList ( vo );
		setState ( dList,lang );
		
		return dList;
	}
	
	private void setState ( DataList dList,String lang ) throws Exception {
		// ,ord.ISLGI,ord.ISAUDI,ord.ISARRIVE,ord.ISSET,ord.ISTOSUP
		DictionaryCache bean = DictionaryCache.getInstance ( );
		List < HashMap > list = dList.getNowlist ( );
		for ( HashMap ot : list ) {
			String s = str ( ot.get ( "ISAUDI" ) )
					+ str ( ot.get ( "ISTOSUP" ) ) + str ( ot.get ( "ISLGI" ) )
					+ str ( ot.get ( "ISARRIVE" ) ) + str ( ot.get ( "ISSET" ) );
			if ( s.equals ( "00000" ) ) {
				ot.put ( "CURRSTATE" , getBizOptionName ( "ORD_ISAUDI" ,
						"0" ,lang) );
			} else if ( s.equals ( "10000" ) ) {
				ot.put ( "CURRSTATE" , getBizOptionName ( "ORD_ISAUDI" ,
						"1",lang ) );
			} else if ( s.equals ( "11000" ) ) {
				ot.put ( "CURRSTATE" , getBizOptionName ( "ORD_ISTOSUP" ,
						"1",lang ) );
			} else if ( s.equals ( "11100" ) ) {
				ot.put ( "CURRSTATE" , getBizOptionName ( "ORD_ISLGI" ,
						"1",lang ) );
			} else if ( s.equals ( "11110" ) ) {
				ot.put ( "CURRSTATE" , getBizOptionName ( "ORD_ISARRIVE" ,
						"1" ,lang) );
			} else if ( s.equals ( "11111" ) ) {
				ot.put ( "CURRSTATE" , getBizOptionName ( "ORD_ISSET" ,
						"1",lang ) );
			} else {
				ot.put ( "CURRSTATE" , "-" );
			}
		}
		
	}
	public String getBizOptionName ( String biztypekey , String bizoptionvalue ,
			String language ) throws Exception {
		DictionaryCache bean = DictionaryCache.getInstance ( );
		BizType bizType = bean.getBizType ( biztypekey );
		for ( Iterator iter = bizType.getOptions ( ).iterator ( ) ; iter
				.hasNext ( ) ; ) {
			BizOption option = ( BizOption ) iter.next ( );
			if ( option.getLanguage ( ).equals ( language )
					&& option.getOptionValue ( ).equals ( bizoptionvalue ) ) {
				return option.getOptionName ( );
			}
		}
		return "";
	}
	
	/**
	 * 新增订单
	 * TODO :::::::::::::::::::::::::::::::::BIZTYPE
	 * @throws Exception
	 */
	public void insertOrder ( HttpServletRequest request , EtCarFrom cForm,List<MyEtOrder_VO> itemList )
			throws Exception {
		OrderTrack pOrder = new OrderTrack ( );
		// lgi
		pOrder.setCustid ( cForm.getCustid ( ) );
		
		if ( "C".equals ( cForm.getPayway ( ) ) ) {
			pOrder.setPayway ( "C" );
		} else if ( "B".equals ( cForm.getPayway ( ) ) ) {
			pOrder.setPayway ( "B" );
			pOrder.setInvno ( cForm.getInvno ( ) );
		}
		
		if ( request.getParameter ( "link_lid" ) == null
				|| request.getParameter ( "link_lid" ).equals ( "" ) ) {
			pOrder.setPostcom ( request.getParameter ( "comname" ) );
			pOrder.setPosttax ( request.getParameter ( "billcode" ) );
			pOrder.setPosttel ( request.getParameter ( "bankno" ) );
			pOrder.setPostaddr ( request.getParameter ( "address" ) );
			pOrder.setPoststate ( request.getParameter ( "state" ) );
			pOrder.setPostcity ( request.getParameter ( "city" ) );
			pOrder.setPostzip ( request.getParameter ( "zipcode" ) );
		}
		
		if ( request.getParameter ( "lic_lid" ) == null
				|| request.getParameter ( "lic_lid" ).equals ( "" ) ) {
			pOrder.setLicno ( request.getParameter ( "licno" ) );
			pOrder.setLiclever ( request.getParameter ( "liclever" ) );
			pOrder.setLicexpire ( request.getParameter ( "licexpire" ) );
			pOrder.setLicaddr ( request.getParameter ( "licaddr" ) );
			pOrder.setLicstate ( request.getParameter ( "licstate" ) );
			pOrder.setLiccity ( request.getParameter ( "liccity" ) );
			pOrder.setLiczip ( request.getParameter ( "liczip" ) );
		}
		
		if(request.getParameter ( "sb_lid" )==null||
				request.getParameter ( "sb_lid" ).equals ( "" )){
			pOrder.setSbilladd ( request.getParameter ( "sbilladd") );
			pOrder.setSbillcity ( request.getParameter ( "sbillcity") );
			pOrder.setSbillstate ( request.getParameter ( "sbillstate") );
			pOrder.setSbilltax ( request.getParameter ( "sbilltax") );
			pOrder.setSbilltel ( request.getParameter ( "sbilltel") );
			pOrder.setSbillzip ( request.getParameter ( "sbillzip") );
			pOrder.setSbcom ( request.getParameter ( "sbcom") );
		}
		
		String [ ] shcarid = request.getParameterValues ( "shcarid" );
		if ( shcarid == null || shcarid.length <= 0 ) {
			throw new Exception ( BIZ.ERROR_SHOPING_NULL );
		}
		MyEtOrder_VO etvo = new MyEtOrder_VO ( );
		etvo.setUserid ( cForm.getUserid ( ) );
		etvo.setKeyids ( shcarid );
		
			Integer orderid = null;
	
		for ( MyEtOrder_VO pvo : itemList ) {
			
			
			OrderTrack order = new OrderTrack ( );
			PropertyUtils.copyProperties ( order , pOrder );
			order.setOrderid ( orderid );
			order.setDetailid ( null );
			order.setCustid ( cForm.getCustid ( ) );
			pvo.setUserid ( cForm.getUserid ( ) );
			pvo.setCountry_ZH ( cForm.getCountry_ZH ( ) );
			
			if ( pvo.getItemtype ( ).equals ( BIZ.TYPES_TEL ) ) {
				ProVO detailOrder = getDetailTel ( pvo , order );
				if ( detailOrder == null )
					throw new Exception ( BIZ.ERROR_SHOPING_EXPIRE );
				PropertyUtils.copyProperties ( order , detailOrder );
				
				if ( detailOrder.getSerplan ( ) != null
						&& detailOrder.getSerplan ( ).indexOf ( "_/__/_" ) < 0 )
					order.setBiztype ( "升级" ) ;
				else 
					order.setBiztype ( "新开" ) ;
				order.setItemtype ( pvo.getItemtype ( ) );
				orderid = mng_OrderService.updateOrder ( order , request );
				
			} else if ( pvo.getItemtype ( ).equals ( BIZ.TYPES_CERT ) ) {
				ProVO detailOrder = getDetailCard ( pvo , order );
				if ( detailOrder == null )
					throw new Exception ( BIZ.ERROR_SHOPING_EXPIRE );
				PropertyUtils.copyProperties ( order , detailOrder );
				
				
				order.setItemtype ( pvo.getItemtype ( ) );
				orderid = mng_OrderService.updateOrder ( order , request );
				
			} else if ( pvo.getItemtype ( ).equals ( BIZ.TYPES_PC ) ) {
				ProVO detailOrder = getDetailPc ( pvo , order );
				if ( detailOrder == null )
					throw new Exception ( BIZ.ERROR_SHOPING_EXPIRE );
				PropertyUtils.copyProperties ( order , detailOrder );
				
				if ( detailOrder.getSerplan ( ) != null
						&& detailOrder.getSerplan ( ).indexOf ( "_/__/_" ) < 0 )
					order.setBiztype ( "升级" ) ;
				else 
					order.setBiztype ( "新开" ) ;
				
				order.setItemtype ( pvo.getItemtype ( ) );
				orderid = mng_OrderService.updateOrder ( order , request );
				
			} else if ( pvo.getItemtype ( ).equals ( BIZ.TYPES_SAFE ) ) {
				ProVO detailOrder = getDetailSafe ( pvo , order );
				if ( detailOrder == null )
					throw new Exception ( BIZ.ERROR_SHOPING_EXPIRE );
				order.setItemtype ( pvo.getItemtype ( ) );
				for ( int i = 0 ; i < order.getSalenum ( ).intValue ( ) ; i ++ ) {
					PropertyUtils.copyProperties ( order , detailOrder );
				//	System.out.println ( "==========order.getItemimg ( )====" + order.getItemimg ( ) );
					order.setOrderid ( null );
					order.setDetailid ( null );
					order.setInfoid ( null );
					orderid = mng_OrderService.updateOrder ( order , request );
				}
				
			} else if ( pvo.getItemtype ( ).equals ( BIZ.TYPES_TV ) ) {
				ProVO detailOrder = getDetailTV ( pvo , order );
				if ( detailOrder == null )
					throw new Exception ( BIZ.ERROR_SHOPING_EXPIRE );
				
				order.setItemtype ( pvo.getItemtype ( ) );
				for ( int i = 0 ; i < order.getSalenum ( ).intValue ( ) ; i ++ ) {
					PropertyUtils.copyProperties ( order , detailOrder );
					
					order.setOrderid ( null );
					order.setInfoid ( null );
					order.setDetailid ( null );
					orderid = mng_OrderService.updateOrder ( order , request );
				}
				
			} else {
				throw new Exception ( BIZ.ERROR_SHOPING_EXPIRE );
			}
			
			order.setOrderid ( orderid );
			
			if ( pvo.getItemtype ( ).equals ( BIZ.TYPES_SAFE ) ) {
				orderid = null;
			} else if ( pvo.getItemtype ( ).equals ( BIZ.TYPES_TV ) ) {
				orderid = null;
			}
			pvo = null;
			
			
			
		}
		 
		// 保存信用卡
		// 保存发票
		// 物流信息
		// 插入订单 主 细 相关 表
		// 
		
	}
	
	public ProVO getDetailCard ( MyEtOrder_VO et , ProVO order )
			throws Exception {
		
		if ( order == null )
			order = new ProVO ( );
		
		Map < String , Object > map = new HashMap < String , Object > ( );
		map.put ( proInterface.PROTYPE_KEY , Const.PRO_TYPE_CART );
		map.put ( proInterface.PROID_KEY , Long.valueOf ( et.getItemid ( ) ) );
		map.put ( proInterface.COUNTRY_KEY , et.getCountry_ZH ( ) );
		
		Object obj = null;
		try {
			obj = proInterface.getPro ( map );
		} catch ( Exception e ) { 
			e.printStackTrace ( );
		}
		if(obj==null)return null;
		Card card = ( Card ) obj;
		
		order.setItemtype ( BIZ.TYPES_CERT );
		order.setItemtitle ( card.getProTitle ( ) );// 商品名称
		order.setItemid ( card.getProId ( ).intValue ( ) );// '商品详细信息ID',
		order.setItemimg ( card.getCardImg ( ) );
		order.setSalenum ( et.getSalenum ( ) ); // '购买数量',
		order.setSupid ( String.valueOf ( card.getProSupplierId ( )) );// '运营商',信用卡所属银行
		order.setSupname ( card.getProSupplierName ( ) ); // '运营商',信用卡所属银行 
		order.setItemkind ( card.getCardTypev ( ).getCardTypeName ( ) );// '商品类型；信用卡类型 
		order.setItemkindID ( card.getCardTypev ( ).getCardTypeId (  ).toString ( ) );
		order.setSerpid (String.valueOf (card.getCardServicePlanv ( ).getCardServicePlanId ( )));
//		card.servicePlanName 
		order.setSerplan (card.getCardServicePlanv ( ).getCardServicePlanName ( )); // 信用卡服务计划??
		/*MessageManager mm=ViewsMessageManager.get ( );
		String servicePlanName=mm.getMessage ( "card.servicePlanName" );
		order.setFullDesc_serplan ( servicePlanName+":"+order.getSerplan ( ) );*/
		Double prix=card.getPrice ( );
		prix=prix==null?new Double ( 0 ):prix;
		order.setPrix ( prix ); // '商品原始价格',
		order.setUnitprice ( prix ); // '商品销售价格',
		order.setIntegral ( card.getIntegral ( ) );
		order.setOperType ( String.valueOf ( card.getProOnOffStatus ( )
				.intValue ( ) ) );
		
		return order;
	}
	
	public ProVO getDetailTV ( MyEtOrder_VO et , ProVO order )
			throws Exception {
		if ( order == null )
			order = new ProVO ( );
		
		Map < String , Object > map = new HashMap < String , Object > ( );
		map.put ( proInterface.PROTYPE_KEY , Const.PRO_TYPE_TV );
		map.put ( proInterface.PROID_KEY , Long.valueOf ( et.getItemid ( ) ) );
		map.put ( proInterface.COUNTRY_KEY , et.getCountry_ZH ( ) );
		
		Object obj = null;
		try {
			obj = proInterface.getPro ( map );
		} catch ( Exception e ) { 
			e.printStackTrace ( );
		}
		if(obj==null)return null;
		
		DigitalTv digitaltv = ( DigitalTv )obj;
		order.setItemtype ( BIZ.TYPES_TV );
		order.setItemtitle ( digitaltv.getProTitle ( ) );// 商品名称
		order.setItemid ( digitaltv.getProId ( ).intValue ( ) );// '商品详细信息ID',
		order.setItemimg ( digitaltv.getDtImage  ( ) );
		order.setSalenum ( et.getSalenum ( ) ); // '购买数量',
		order.setItemkind ( digitaltv.getDigitalTvSpeedType ( ).getDigitalTvTypeName ( ) );// '商品类型 
		order.setItemkindID ( digitaltv.getDigitalTvSpeedType ( ).getdSpeedTypeTypeId ( ).toString ( ) );
		order.setSupname ( digitaltv.getProSupplierName ( ) ); // 运营商
		order.setSupid ( String.valueOf (digitaltv.getProSupplier ( ).getProSupplierId ( )) );
		
		Double prix=digitaltv.getPrice ( ); 
		prix=prix==null?new Double ( 0 ):prix;
		order.setPrix ( prix ); // '商品原始价格',
		order.setUnitprice ( prix ); // '商品销售价格', 
		order.setIntegral ( digitaltv.getIntegral ( ) );
		order.setOperType ( String.valueOf ( digitaltv.getProOnOffStatus ( )
				.intValue ( ) ) );
		return order;
	}
	
	public ProVO getDetailPc ( MyEtOrder_VO et , ProVO order )
			throws Exception {
		if ( order == null )
			order = new ProVO ( );
		
		Map < String , Object > map = new HashMap < String , Object > ( );
		map.put ( proInterface.PROTYPE_KEY , Const.PRO_TYPE_NETBOOK );
		map.put ( proInterface.PROID_KEY , Long.valueOf ( et.getItemid ( ) ) );
		map.put ( proInterface.PROCOLOR_KEY , et.getItemkindID( ) );
		
		map.put ( proInterface.COUNTRY_KEY , et.getCountry_ZH ( ) );
		map.put ( proInterface.PROCOLOR_NAME_KEY , et.getItemkind ( ) );
		map.put ( proInterface.PROSERVICEID_KEY , et.getSerpid ( ) );
		
		Object obj = null;
		try {
			obj = proInterface.getPro ( map );
		} catch ( Exception e ) { 
			e.printStackTrace ( );
		}
		if(obj==null)return null;
		
		NetBook netbook = ( NetBook ) obj;
		order.setItemtype ( BIZ.TYPES_PC );
		order.setItemtitle ( netbook.getProTitle ( ) );// 商品名称
		order.setItemid ( netbook.getProId ( ).intValue ( ) );// '商品详细信息ID',
		order.setSalenum ( et.getSalenum ( ) ); // '购买数量',
		List < ProImage > pis = netbook.getProImages ( );
		if ( pis != null && pis.size ( ) > 0 )
			order.setItemimg ( netbook.getProImages ( ).get ( 0 ).getPropsm ( ) );
		order.setItembrand ( netbook.getBrand ( ).getBrandDesc ( ) ); // 品牌
		order.setItemkind ( et.getItemkind ( ) );// 颜色
		order.setItemkindID ( et.getItemkindID ( ) );
		order.setSupname ( netbook.getProSupplierName ( ) ); // '运营商',信用卡所属银行
		order.setSupid ( String.valueOf ( netbook.getProSupplierId ( ) ) ); // 
		order.setItemmodel ( netbook.getModel ( ) ); // 型号
		order.setSerpid ( String.valueOf ( netbook.getOrderProService ( ).getProServiceId ( ) ) ); // 服务计划ID 
		order.setSerplan ( 
				netbook.getOrderProService().getProPlanName ( )
				+BIZ.sKey+str(netbook.getOrderProService ( ).getProServiceAnytimeMinutes ( ))+
				BIZ.sKey+ str(netbook.getOrderProService ( ).getProServiceNightsWeekends ( ))+
				BIZ.sKey+str(netbook.getOrderProService ( ).getProServiceMonthlyFee ( ))+
				BIZ.sKey+str(netbook.getOrderProService ( ).getProServiceAdditionalLineMonthlyFee ( ))+
				BIZ.sKey+str(netbook.getOrderProService ( ).getProServiceFeatures ( ))+
				BIZ.sKey); 
		order.setSerplanArr ( order.getSerplan ( ).split ( BIZ.sKey ));
		//System.out.println ("======================getSerplan==: "+order.getSerplan());
		//System.out.println ("======================getSerplan==: "+order.getSerplanArr ( ).length);
		/*MessageManager mm=ViewsMessageManager.get ( );
		String servicePlanName=mm.getMessage ( "pro.service.splanname" )+":"+netbook.getOrderProService().getProPlanName ( )
		+BIZ.sKey+mm.getMessage ( "pro.service.AnytimeMinutes" )+":"+netbook.getOrderProService ( ).getProServiceAnytimeMinutes ( )+
		BIZ.sKey+ mm.getMessage ( "pro.service.NightsWeekends" )+":"+netbook.getOrderProService ( ).getProServiceNightsWeekends ( )+
		BIZ.sKey+mm.getMessage ( "pro.service.MonthlyFee" )+":"+netbook.getOrderProService ( ).getProServiceMonthlyFee ( )+
		BIZ.sKey+mm.getMessage ( "pro.service.Features" )+":"+netbook.getOrderProService ( ).getProServiceFeatures ( )+
		BIZ.sKey;		
		order.setFullDesc_serplan ( servicePlanName );*/
		
		order.setItembrand ( netbook.getBrandEgn ( ) );
		
		Double prix=netbook.getPrice ( ); 
		prix=prix==null?new Double ( 0 ):prix;
		
		Double deprix = netbook.getDisPrice ( ); 
		deprix = deprix==null?new Double ( 0 ):deprix;
		
		order.setPrix ( netbook.getPrice ( ) ); // '商品原始价格',
		order.setUnitprice (deprix!=null?deprix:prix ); // '商品销售价格',
		order.setDeprix ( deprix ); // 折扣
		String fee = netbook.getOrderProService ( ).getProServiceMonthlyFee ( );
		order.setServMonthlyFee ( fee == null ? new Double ( 0 ) : new Double (
				fee ) );// 月费用 
		String addfee=netbook.getOrderProService ( ).getProServiceAdditionalLineMonthlyFee ( );
		order.setProServiceAdditionalLineMonthlyFee ( addfee == null ? new Double ( 0 ) : new Double (addfee ) );
		order.setIntegral ( netbook.getIntegral ( ) );
		order.setOperType ( String.valueOf ( netbook.getProOnOffStatus ( )
				.intValue ( ) ) );
		return order;
	}
	
	public ProVO getDetailTel ( MyEtOrder_VO et , ProVO order )
			throws Exception {
		if ( order == null )
			order = new ProVO ( );
		Map < String , Object > map = new HashMap < String , Object > ( );
		map.put ( proInterface.PROTYPE_KEY , Const.PRO_TYPE_CELLPHONE );
		map.put ( proInterface.PROID_KEY , Long.valueOf ( et.getItemid ( ) ));
		map.put ( proInterface.PROCOLOR_KEY , et.getItemkindID ( ) );
		map.put ( proInterface.PROCOLOR_NAME_KEY , et.getItemkind ( ) );
		map.put ( proInterface.PROSERVICEID_KEY , et.getSerpid ( ) );
		map.put ( proInterface.COUNTRY_KEY , et.getCountry_ZH ( ) );
		
		
		Object obj = null;
		try {
			obj = proInterface.getPro ( map );
		} catch ( Exception e ) { 
			e.printStackTrace ( );
		}
		if(obj==null)return null;
		CellPhone cellphone = ( CellPhone ) obj;
		order.setItemtype ( BIZ.TYPES_TEL );
		order.setItemtitle ( cellphone.getProTitle ( ) );// 商品名称
		order.setItemid ( cellphone.getProId ( ).intValue ( ) );// '商品详细信息ID',
		order.setSalenum ( et.getSalenum ( ) ); // '购买数量',
		List < ProImage > pis = cellphone.getProImages ( );
		if ( pis != null && pis.size ( ) > 0 )
			order.setItemimg ( cellphone.getProImages ( ).get ( 0 ).getPropsm ( ) );
		
		order.setItembrand ( cellphone.getBrandEgn ( ) ); // 品牌
		order.setItemkind ( et.getItemkind ( ) ); // 颜色
		order.setItemkindID ( et.getItemkindID ( ) );
		order.setSupname ( cellphone.getProSupplierName ( ) ); // '运营商',信用卡所属银行
		order.setSupid ( String.valueOf ( cellphone.getProSupplierId ( ) ) );
		order.setItemmodel ( cellphone.getModel ( ) ); // 商品型号
		order.setSerpid ( String.valueOf ( cellphone.getOrderProService ( ).getProServiceId ( ) ) ); // 服务计划ID
		order.setSerplan ( 
				cellphone.getOrderProService().getProPlanName ( )
				+BIZ.sKey+str(cellphone.getOrderProService ( ).getProServiceAnytimeMinutes ( ))+
				BIZ.sKey+ str(cellphone.getOrderProService ( ).getProServiceNightsWeekends ( ))+
				BIZ.sKey+str(cellphone.getOrderProService ( ).getProServiceMonthlyFee ( ))+
				BIZ.sKey+str(cellphone.getOrderProService ( ).getProServiceAdditionalLineMonthlyFee ( )) +
				BIZ.sKey+str(cellphone.getOrderProService ( ).getProServiceFeatures ( ))+
				BIZ.sKey);
		order.setSerplanArr ( order.getSerplan ( ).split ( BIZ.sKey ));
		/*MessageManager mm=ViewsMessageManager.get ( );
		String servicePlanName=mm.getMessage ( "pro.service.splanname" )+":"+cellphone.getOrderProService().getProPlanName ( )
		+BIZ.sKey+mm.getMessage ( "pro.service.AnytimeMinutes" )+":"+cellphone.getOrderProService ( ).getProServiceAnytimeMinutes ( )+
		BIZ.sKey+ mm.getMessage ( "pro.service.NightsWeekends" )+":"+cellphone.getOrderProService ( ).getProServiceNightsWeekends ( )+
		BIZ.sKey+mm.getMessage ( "pro.service.MonthlyFee" )+":"+cellphone.getOrderProService ( ).getProServiceMonthlyFee ( )+
		BIZ.sKey+mm.getMessage ( "pro.service.Features" )+":"+cellphone.getOrderProService ( ).getProServiceFeatures ( )+
		BIZ.sKey;		
		order.setFullDesc_serplan ( servicePlanName );*/

		Double prix=cellphone.getPrice ( ); 
		prix=prix==null?new Double ( 0 ):prix;
		
		Double deprix = cellphone.getDisPrice ( ); 
		deprix = deprix==null?new Double ( 0 ):deprix;
		
		order.setPrix ( prix ); // '商品原始价格',
		order.setUnitprice ( deprix==null?prix:deprix ); // '商品销售价格',
		order.setDeprix ( deprix ); // 折扣
		String fee = cellphone.getOrderProService ( ).getProServiceMonthlyFee ( );
		order.setServMonthlyFee ( fee == null ? new Double ( 0 ) : new Double (fee ) );// 月费用
		// 少加线费用
		String addfee=cellphone.getOrderProService ( ).getProServiceAdditionalLineMonthlyFee ( );
		order.setProServiceAdditionalLineMonthlyFee ( addfee == null ? new Double ( 0 ) : new Double (addfee ) );
		order.setIntegral ( cellphone.getIntegral ( ) );
		order.setOperType ( String.valueOf ( cellphone.getProOnOffStatus ( )
				.intValue ( ) ) );
		return order;
	}
	
	public ProVO getDetailSafe ( MyEtOrder_VO et , ProVO order )
			throws Exception {
		if ( order == null )
			order = new ProVO ( );
		Map < String , Object > map = new HashMap < String , Object > ( );
		map.put ( proInterface.PROTYPE_KEY , Const.PRO_TYPE_SS );
		map.put ( proInterface.PROID_KEY , Long.valueOf ( et.getItemid ( ) ) );
		map.put ( proInterface.COUNTRY_KEY , et.getCountry_ZH ( ) );
		
		Object obj = null;
		try {
			obj = proInterface.getPro ( map );
		} catch ( Exception e ) { 
			e.printStackTrace ( );
		}
		if(obj==null)return null;
		SecurityDoor securitydoor = ( SecurityDoor )obj;
		order.setItemtype ( BIZ.TYPES_SAFE );
		order.setItemtitle ( securitydoor.getProTitle ( ) );// 商品名称
		order.setItemid ( securitydoor.getProId ( ).intValue ( ) );// '商品详细信息ID',
		order.setSalenum ( et.getSalenum ( ) ); // '购买数量',
		order.setItemimg ( securitydoor.getSsImage ( ) );
		order.setItemkind ( securitydoor.getSsType ( ).getSdTypeName ( ) ); // 类型
		order.setItemkindID ( securitydoor.getSsType ( ).getSdTypeId ( ).toString ( ) );
		order.setSupname ( securitydoor.getProSupplierName ( ) ); // '运营商' 
		order.setSupid ( String.valueOf ( securitydoor.getProSupplierId ( ) ) );
		order.setPrix ( securitydoor.getPrice ( ) ); // '商品原始价格',
		order.setUnitprice ( securitydoor.getPrice ( ) ); // '商品销售价格',
		order.setIntegral ( securitydoor.getIntegral ( ) );
		order.setOperType ( String.valueOf ( securitydoor.getProOnOffStatus ( )
				.intValue ( ) ) );
		return order;
	}
	
	private String str ( Object o ) {
		if ( o == null )
			return "";
		else
			return o.toString ( );
	}
	
	/**
	 * 个人信息查询
	 */
	public void myInfoQuery ( ) {
		
	}
	
	/**
	 * 个人信息更新
	 * 
	 * @throws Exception
	 */
	public void updateMyInfo ( CustBaseVo vo ) throws Exception {
		CustBaseVo custbasevo = new CustBaseVo ( );
		custbasevo.setCustid ( vo.getCustid ( ) );
		
		custbasevo = mng_CustDao.loadCust ( custbasevo );
		if ( custbasevo == null )
			throw new Exception ( BIZ.ERROR_NULL );
		if(vo.getSafeno ( )!=null&&vo.getSafeno ( ).indexOf ( "*" )!=-1){
			vo.setSafeno ( null );
		}
		mng_CustDao.updateCustBaseInfo ( vo );
	}
	
	/**
	 * 我的购物车
	 */
	public void myShopBagQuery ( ) {
		
	}
	
	/**
	 * 我的购物车
	 */
	public int updateShopBagQuery ( MyEtOrder_VO vo ) {
		return m_IMyEt_UCenterDao.insert_ET_SHOPCAR ( vo );
	}
	
	/**
	 * 货运地址维护
	 */
	public int updateUserLgi ( CustInfoVo info ) {
		if("1".equals ( info.getDefaultflag ( ))){
			CustInfoVo clear=new CustInfoVo();
			clear.setCustid ( info.getCustid ( ) );
			clear.setDtype ( info.getDtype ( ) );
			clear.setDefaultflag ( "0" ); 
			mng_CustDao.update_pub_cust_info ( clear );
		}else{
			info.setDefaultflag ( "0" );
		}
		//System.out.println ("//"+info.getDefaultflag ( )+"//"+info.getBillcode ( ));
		if ( info.getLid ( ) != null ) {
			return mng_CustDao.update_pub_cust_info ( info );
		} else
			mng_CustDao.insertCustMsg ( info );
		return 0;
		
	}
	
	public int updateUserLgiDefault ( CustInfoVo info ) {
		
		if(null == info.getLid ( )) return 0;
		
		CustInfoVo clear=new CustInfoVo();
		clear.setCustid ( info.getCustid ( ) );
		clear.setDtype ( info.getDtype ( ) );
		clear.setDefaultflag ( "0" );
		
		mng_CustDao.update_pub_cust_info ( clear );
		
		return mng_CustDao.update_pub_cust_info ( info );		
	}
	
	public int update_Session_ET_SHOPCAR ( MyEtOrder_VO vo ) {
		return m_IMyEt_UCenterDao.update_Session_ET_SHOPCAR ( vo );
	}
	
	/**
	 * 更新购物车商品属性
	 * 
	 * @param list
	 */
	public void update_Et_shopSupId (String[] shcarid,String[] buynum ) { 
			MyEtOrder_VO pvo =null;
			for(int i=0;i<shcarid.length;i++){
				pvo =new MyEtOrder_VO();
				pvo.setShcarid ( new Integer(shcarid[i]) );
				pvo.setSalenum ( new Integer(buynum[i]) );
				m_IMyEt_UCenterDao.update_ET_SHOPCAR ( pvo ); 
			}
	}
	
	public List queryList_ET_SHOPCAR(MyEtOrder_VO loadvo) throws Exception{ 
	
		List < MyEtOrder_VO > datalist = m_IMyEt_UCenterDao.queryList_ET_SHOPCAR ( loadvo );

		List < MyEtOrder_VO > glist=new ArrayList < MyEtOrder_VO >();
		for ( MyEtOrder_VO et : datalist ) {
			
			et.setCountry_ZH ( loadvo.getCountry_ZH ( ) );
			String itemtype = et.getItemtype ( );
			ProVO detail = new ProVO ( );
			if ( itemtype.equals ( BIZ.TYPES_CERT ) ) {
				detail = getDetailCard ( et , null );
				
			} else if ( itemtype.equals ( BIZ.TYPES_PC ) ) {
				detail = getDetailPc ( et , null );
				
			} else if ( itemtype.equals ( BIZ.TYPES_SAFE ) ) {
				detail = getDetailSafe ( et , null );
				
			} else if ( itemtype.equals ( BIZ.TYPES_TEL ) ) {
				detail = getDetailTel ( et , null );
				
			} else if ( itemtype.equals ( BIZ.TYPES_TV ) ) {
				detail = getDetailTV ( et , null );
				
			}
			if(detail==null)continue;
			MyEtOrder_VO pvo=new MyEtOrder_VO();
			PropertyUtils.copyProperties ( pvo , detail );
			pvo.setShcarid ( et.getShcarid ( ) );
			pvo.setSalenum ( et.getSalenum ( ) );
			glist.add ( pvo);
			
		}
		return glist;
	}

	
	
}